#include <bits/stdc++.h>
// 2025/04/04
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int n, a[201], dp[201][201];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], a[i + n] = a[i];
    for (int len = 2; len <= n; len++)
        for (int l = 1, r = len; r <= n + n - 1; l++, r++){
            for (int k = l; k < r; k++)
                dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r] + a[l] * a[k + 1] * a[r + 1]);
        }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, dp[i][i + n - 1]);
    cout << ans << endl;
    return 0;
}